﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Telerik.Web.UI;
using SMA.GENTEv1;

public partial class Protegidos_Administracao_Cadastros_acAltContratoVigencia : System.Web.UI.Page
{
    protected int idContrato = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["idContrato"] != null)
            idContrato = Int32.Parse(Request.QueryString["idContrato"].ToString());

        if (idContrato != 0)
        {
            CarregarDadosContrato();
            CarregarDadosAtualizacao();
            CarregarDadosGestor();
        }
        else
        {
            Response.Redirect("acContratoVigencia.aspx");
        }
    }

    #region Eventos

    #region Eventos - Geral
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument == "RebindGestor")
        {
            RadGrid2.MasterTableView.SortExpressions.Clear();
            RadGrid2.MasterTableView.GroupByExpressions.Clear();
            RadGrid2.MasterTableView.CurrentPageIndex = RadGrid2.MasterTableView.PageCount - 1;
            RadGrid2.Rebind();
        }
        //if (e.Argument == "Rebind")
        //{
        //    if (Session["ContratoFile"] != null)
        //    {
        //        lnkImage.Visible = false;
        //        lblImage.Text = "Arquivo ''" + Session["ContratoFile"].ToString() + "'' incluído com sucesso.";
        //    }
        //}
        //else if (e.Argument == "RebindAndNavigate")
        //{
        //    RadGrid1.MasterTableView.SortExpressions.Clear();
        //    RadGrid1.MasterTableView.GroupByExpressions.Clear();
        //    RadGrid1.MasterTableView.CurrentPageIndex = RadGrid1.MasterTableView.PageCount - 1;
        //    RadGrid1.Rebind();
        //}
    }
    #endregion

    #region Eventos - Atualizacao
    #endregion

    #region Eventos - Gestores
    protected void RadGrid2_DeleteCommand(object source, GridCommandEventArgs e)
    {
        int idContratoGestor = int.Parse((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["IdContratoGestor"].ToString());

        ContratoGestor contratoGestor = new ContratoGestor();
        contratoGestor.IdContratoGestor = idContratoGestor;
        contratoGestor.Excluir();

        CarregarDadosGestor();
    }
    #endregion

    #endregion

    #region Metodos

    #region Metodos - Geral
    protected void CarregarDadosContrato()
    {
        Contrato contrato = new Contrato(idContrato);

        lblTitulo.Text = contrato.Descricao;
        lnkImage.HRef = "http://localhost/gentev1/" + contrato.Path;
        lblInicio.Text = contrato.DataInicioVigencia.ToString();
        lblTermino.Text = contrato.DataFimVigencia.ToString();
        lblProrrogado.Text = contrato.DataProrrogacao.ToString();
        lblRescindido.Text = contrato.DataRescindir.ToString();
        hdId.Value = contrato.IdContrato.ToString();
    }
    #endregion

    #region Metodos - Atualizacao
    protected void CarregarDadosAtualizacao()
    {
        ContratoAditivo contratoAditivo = new ContratoAditivo();
        List<ContratoAditivo> listContratoAditivo = contratoAditivo.SelectPor(idContrato);

        RadGrid1.DataSource = listContratoAditivo;
        RadGrid1.DataBind();
    }
    #endregion

    #region Metodos - Gestores
    protected void CarregarDadosGestor()
    {
        ContratoGestor contratoGestor = new ContratoGestor();
        List<ContratoGestor> listContratoGestor = contratoGestor.SelectPor(idContrato);

        RadGrid2.DataSource = listContratoGestor;
        RadGrid2.DataBind();
    }
    #endregion

    #endregion
}
